/******************************************************************************
 *                  Shanghai ChipON Micro-Electronic Co.,Ltd
 ******************************************************************************
 *  @File Name        : kf8a100fxx_ccp.h
 *  @Author           : ChipON AE/FAE Group
 *  @Date             : 2023-12-19
 *  @HW Version       : KF8A100Fxx
 *  @Lib Version      : V2.0.1
 *  @Description      : This file provides the driver for the ccp module
 ******************************************************************************
 *  Copyright (C) by Shanghai ChipON Micro-Electronic Co.,Ltd
 *  All rights reserved.
 *
 *  This software is copyright protected and proprietary to
 *  Shanghai ChipON Micro-Electronic Co.,Ltd.
 *****************************************************************************/
/******************************************************************************
 *  |Date        |Version  |Author       |Description
 ******************************************************************************
 *  |2023-12-25  |V2.0     |Wang Junxiong|New creat
 *****************************************************************************/

#ifndef KF8A100FXX_CCP_H
#define KF8A100FXX_CCP_H

#ifdef __cplusplus
extern "C" {
#endif

/******************************************************************************
 *                      Include Files
 *****************************************************************************/
#include "kf8a100fxx.h"
/******************************************************************************
 *                      Macro or Inline
 *****************************************************************************/

/**
 * @brief ccp module disable/enable
 * 0: disable, 1:enable
 *
 */
#define CCP3_ENABLE(x) (T3ON = (x))
#define CCP4_ENABLE(x) (T4ON = (x))
#define CCP5_ENABLE(x) (T1ON = (x))
/*****************************************************************************
 *                      Typedef Definitions
 *****************************************************************************/
/**
 * @brief Ccp reload enabled
 */
typedef enum
{
    CCP_RELOAD_DISABLE = 0u,
    CCP_RELOAD_ENABLE  = 128u
} Ccp_ReloadType;

/**
 * @brief CCP5 prescale
 */
typedef enum
{
    CCP5_PRESCALER_1 = 0u,
    CCP5_PRESCALER_2 = 16u,
    CCP5_PRESCALER_4 = 32u,
    CCP5_PRESCALER_8 = 48u
} Ccp5_PrescalerType;

/**
 * @brief CCP5 clock source
 */
typedef enum
{
    /** @brief High frequency internal crystal: 16MHz */
    CCP5_SOURCE_INTHF = 1u,
    /** @brief System clock/4 */
    CCP5_SOURCE_SCLKDIV4 = 0u
} Ccp5_SourceType;

/**
 * @brief Ccp 3 4 prescale
 */
typedef enum
{
    CCP3_4_PRESCALER_1 = 0u,
    CCP3_4_PRESCALER_2 = 16u,
    CCP3_4_PRESCALER_4 = 32u,
    CCP3_4_PRESCALER_8 = 48u
} Ccp3_4_PrescalerType;

/**
 * @brief Ccp 3 4 compare mode output enable bit
 */
typedef enum
{
    CCP3_4_OUTPUT_ENABLE  = 16u,
    CCP3_4_OUTPUT_DISABLE = 0u,
} Ccp3_4_OutputType;

/**
 * @brief Ccp 3 4 clock source
 */
typedef enum
{
    /** @brief Internal High Frequency Crystal */
    CCP3_4_SOURCE_INTHF = 0u,
    /** @brief Internal low frequency crystal */
    CCP3_4_SOURCE_INTLF = 2u,
    /** @brief External High Frequency Crystal */
    CCP3_4_SOURCE_EXTHF = 4u,
} Ccp3_4_SourceType;

/**
 * @brief Ccp 3 4 capture mode
 */
typedef enum
{
    CCP_CAPTURE_DISABLE               = 0u,
    CCP_CAPTURE_EACH_FALLING_EDGE     = 4u,
    CCP_CAPTURE_EACH_RISING_EDGE      = 5u,
    CCP_CAPTURE_EVERY_4_RISING_EDGES  = 6u,
    CCP_CAPTURE_EVERY_16_RISING_EDGES = 7u,
} Ccp_CaptureModeType;

/**
 * @brief Ccp 3 4 compare mode
 */
typedef enum
{
    CCP_COMPARE_DISABLE            = 0u,
    CCP_COMPARE_TOGGLE_GPIO        = 2u,
    CCP_COMPARE_OUTPUTS_HIGH       = 8u,
    CCP_COMPARE_OUTPUTS_LOW        = 9u,
    CCP_COMPARE_SOFTWARE_INTERRUPT = 10u,
    CCP_COMPARE_EVENT              = 11u
} Ccp_CompareModeType;
/******************************************************************************
 *                      Export Variables
 *****************************************************************************/

/******************************************************************************
 *                      Export Functions
 *****************************************************************************/

/**
 * @brief T3 Comparison mode initialization
 *
 * @param Mode Compare mode
 * @param Reload Reload Enable
 * @param Div prescale
 * @param Period T3REH/CCP3H, T3REL/CCP3L
 */
void Ccp3_CompareInit(Ccp_CompareModeType Mode, Ccp_ReloadType Reload, Ccp3_4_PrescalerType Div, uint16_t Period);

/**
 * @brief T4 Comparison mode initialization
 *
 * @param Mode Compare mode
 * @param Reload Reload Enable
 * @param Div prescale
 * @param Period T4REH, T4REL
 */
void Ccp4_CompareInit(Ccp_CompareModeType Mode, Ccp_ReloadType Reload, Ccp3_4_PrescalerType Div, uint16_t Period);

/**
 * @brief T1 CCP5 Comparison mode initialization
 *
 * @param Mode Compare mode
 * @param Reload Reload Enable
 * @param Div prescale
 * @param Period PP2 PWM5L1, PP1 PWM5L0
 */
void Ccp5_CompareInit(Ccp_CompareModeType Mode, Ccp_ReloadType Reload, Ccp5_PrescalerType Div, uint16_t Period);

/**
 * @brief CCP3 set period value
 *
 * @param Period period value
 */
void Ccp3_SetPeriodValue(uint16_t Period);

/**
 * @brief CCP4 set period value
 *
 * @param Period period value
 */
void Ccp4_SetPeriodValue(uint16_t Period);

/**
 * @brief CCP5 set period value
 *
 * @param Period period value
 */
void Ccp5_SetPeriodValue(uint16_t Period);

/**
 * @brief CCP3 set compare mode
 *
 * @param Mode Compare mode
 */
void Ccp3_SetCompareMode(Ccp_CompareModeType Mode);

/**
 * @brief CCP4 set compare mode
 *
 * @param Mode Compare mode
 */
void Ccp4_SetCompareMode(Ccp_CompareModeType Mode);

/**
 * @brief CCP5 set compare mode
 *
 * @param Mode Compare mode
 */
void Ccp5_SetCompareMode(Ccp_CompareModeType Mode);

/**
 * @brief T3 Capture mode initialization
 *
 * @param Mode Capture mode
 * @param Reload Reload Enable
 * @param Div prescale
 * @param Period T3REH, T3REL
 */
void Ccp3_CaptureInit(Ccp_CaptureModeType Mode, Ccp_ReloadType Reload, Ccp3_4_PrescalerType Div, uint16_t Period);

/**
 * @brief T4 Capture mode initialization
 *
 * @param Mode Capture mode
 * @param Reload Reload Enable
 * @param Div prescale
 * @param Period T4REH, T4REL
 */
void Ccp4_CaptureInit(Ccp_CaptureModeType Mode, Ccp_ReloadType Reload, Ccp3_4_PrescalerType Div, uint16_t Period);

/**
 * @brief T1 CCP5 Capture mode initialization
 *
 * @param Mode Capture mode
 * @param Reload Reload Enable
 * @param Div prescale
 * @param Period PP2 PWM5L1, PP1 PWM5L0
 */
void Ccp5_CaptureInit(Ccp_CaptureModeType Mode, Ccp_ReloadType Reload, Ccp5_PrescalerType Div, uint16_t Period);

/**
 * @brief CCP3 gets the capture value
 *
 * @return uint16_t capture value
 */
uint16_t Ccp3_GetCaptureValue(void);

/**
 * @brief CCP4 gets the capture value
 *
 * @return uint16_t capture value
 */
uint16_t Ccp4_GetCaptureValue(void);

/**
 * @brief CCP5 gets the capture value
 *
 * @return uint16_t capture value
 */
uint16_t Ccp5_GetCaptureValue(void);

/**
 * @brief CCP3 set capture mode
 *
 * @param Mode Capture mode
 */
void Ccp3_SetCaptureMode(Ccp_CaptureModeType Mode);

/**
 * @brief CCP4 set capture mode
 *
 * @param Mode Capture mode
 */
void Ccp4_SetCaptureMode(Ccp_CaptureModeType Mode);

/**
 * @brief CCP5 set capture mode
 *
 * @param Mode Capture mode
 */
void Ccp5_SetCaptureMode(Ccp_CaptureModeType Mode);

/**
 * @brief CCP3 disable
 *
 */
void Ccp3_Disable(void);

/**
 * @brief CCP4 disable
 *
 */
void Ccp4_Disable(void);
/**
 * @brief CCP5 disable
 *
 */
void Ccp5_Disable(void);

/**
 * @brief CCP3 Deinitialization
 *
 */
void Ccp3_DeInit(void);

/**
 * @brief CCP4 Deinitialization
 *
 */
void Ccp4_DeInit(void);
/**
 * @brief CCP5 Deinitialization
 *
 */
void Ccp5_DeInit(void);

#ifdef __cplusplus
}
#endif

#endif
/* EOF */
